package com.software.loginregister.entity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import lombok.Data;

@Data
public class MessageResponse {
    private String id;
    private String query;
    private String answer;
    private Long createdAt;
    private String formattedTime;

    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

    // 用于UI显示的格式化时间
    public String getDisplayTime() {
        if (createdAt == null) return "";
        return DATE_FORMAT.format(new Date(createdAt * 1000L)); // 转换为毫秒
    }

    // 设置时间戳时自动格式化时间
    public void setCreatedAt(Long createdAt) {
        this.createdAt = createdAt;
        if (createdAt != null) {
            this.formattedTime = getDisplayTime();
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public Long getCreatedAt() {
        return createdAt;
    }

    public String getFormattedTime() {
        return formattedTime;
    }

    public void setFormattedTime(String formattedTime) {
        this.formattedTime = formattedTime;
    }
}

